import cv2
import numpy as np
 # 读取图像
image = cv2.imread('2.webp', cv2.IMREAD_GRAYSCALE)
if image is None:
     print("Error: Unable to load image.")
     exit()
# # 对数变换
c = 255 / np.log(1 + np.max(image))  # 归一化系数
log_transformed = c * np.log(1 + image)
# # 转换为8位无符号整数
log_transformed = np.uint8(log_transformed)
# # 显示原始图像和对数变换后的图像
cv2.imshow('Original Image', image)
cv2.imshow('Log Transformed Image', log_transformed)
cv2.waitKey(0)
cv2.destroyAllWindows()